<?php

namespace iBrand\Shop\Server\Resources;

use Carbon\Carbon;
use iBrand\Common\Resources\BaseResource;
use iBrand\Component\Balance\Model\Balance;
use iBrand\Component\Point\Model\Point;

class ShopUser extends BaseResource
{
    public function toArray($request)
    {
        $balance = Balance::SumByUser($this->resource->id);
        $this->resource->balance = $balance;

        $point = Point::where('user_id', $this->resource->id)->valid()->sumPoint();
        $this->resource->point = $point;

        $this->resource->user_id = $this->resource->id;

        $year = Carbon::now()->format('Y');
        $check = Point::where('note', '生日购物双倍积分')->where('user_id', $this->resource->id)->where('created_at', 'like', '%' . $year . '%')->get()->first();
        if ($check) {
            $this->resource->birthday = $this->resource->birthday . '已享受生日折扣';
        }

        return parent::toArray($request);
    }
}